package com.qf.boot.service.consumer;

import com.qf.boot.service.api.SiteService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

@EnableAutoConfiguration
public class TimeoutDubboConsumer {

    //一端设置
    //timeout = 6000 客户端时间，默认1秒，+服务端执行了5秒，所以这次请求不会报错
    //timeout = 3000 客户端依然会报错，服务端继续执行完成，服务端不会停止执行，并且客户端会默认重试两次

    //两端都设置
    //消费端 timeout =3000或者4000或者1000、2000只要小于5000，服务端设置4000， 由于服务方执行需要5秒，所以会接着执行，不会停止，然后会记录warn日志,消费方继续报错
    /*
     输出
     serving
     [03/07/24 22:47:01:205 CST] DubboServerHandler-192.168.3.77:20882-thread-2  WARN filter.TimeoutFilter:  [DUBBO] invoke time out. method: getName arguments: [qq-timeout] , url is dubbo://192.168.3.77:20882/com.qf.boot.service.api.SiteService?anyhost=true&application=site-service-boot-provider-version&bean.name=ServiceBean:com.qf.boot.service.api.SiteService:timeout&bind.ip=192.168.3.77&bind.port=20882&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.qf.boot.service.api.SiteService&methods=getName&pid=18272&qos.enable=false&register=true&release=2.7.3&revision=timeout&side=provider&timeout=4000&timestamp=1720017991428&version=timeout, invoke elapsed 5008 ms., dubbo version: 2.7.3, current host: 192.168.3.77
     */
    @Reference(version = "timeout",timeout = 2000)
    private SiteService siteService;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(TimeoutDubboConsumer.class);
        SiteService siteService = (SiteService) context.getBean(SiteService.class);
        String name =  siteService.getName("qq-timeout");
        System.out.println(name);
    }

}
